package com.billionsfinance.hessian.model;

import com.billionsfinance.hessian.common.utils.ZkPathBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;

/**
 * 服务信息,包括路径和值
 *
 * @ FileName: ServerInfo.java
 * @ Author: WeiHui-Z
 * @ Date: 2016-11-23  14:12
 * @ Version: v1.0.0
 */
public class ServerInfo {

	private String group;  // eg: crs

	private String edition;  // eg: 1.0.0

	private String simpleName;  // eg: HelloServer

	private String name;  // eg: com.xxx.HelloServer

	private String author; //作者，for web

	private String desc; //接口描述，for web

	private String url; //hessian服务地址，for web  http://127.0.0.1:8080/v4

	private String path; // zookeeper path eg: /crs/com.xxx.HelloServer:1.0.0/

	private int connTimeout; //hessian连接超时时间，for web

	private int readTimeout;  //hessian读取超时时间，for web

	private String data;  // eg: http://127.0.0.1:8080/v4/Hessian/HelloServer,60,60

	public ServerInfo(String group, String edition, String simpleName, String name, String author, String desc, String url, int connTimeout, int readTimeout) {
		this.group = group;
		this.edition = edition;
		this.simpleName = simpleName;
		this.name = name;
		this.author = author;
		this.desc = desc;
		this.url = url + simpleName;
		this.connTimeout = connTimeout;
		this.readTimeout = readTimeout;

		this.path = ZkPathBuilder.buildPath(group, name, edition);
		this.data = StringUtils.joinWith(",", this.url, connTimeout, readTimeout);
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public String getEdition() {
		return edition;
	}

	public void setEdition(String edition) {
		this.edition = edition;
	}

	public String getSimpleName() {
		return simpleName;
	}

	public void setSimpleName(String simpleName) {
		this.simpleName = simpleName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public int getConnTimeout() {
		return connTimeout;
	}

	public void setConnTimeout(int connTimeout) {
		this.connTimeout = connTimeout;
	}

	public int getReadTimeout() {
		return readTimeout;
	}

	public void setReadTimeout(int readTimeout) {
		this.readTimeout = readTimeout;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this)
				.append("group", group)
				.append("edition", edition)
				.append("simpleName", simpleName)
				.append("name", name)
				.append("author", author)
				.append("desc", desc)
				.append("url", url)
				.append("path", path)
				.append("connTimeout", connTimeout)
				.append("readTimeout", readTimeout)
				.append("data", data)
				.toString();
	}
}
